﻿package com.billow.utils
{
	import com.billow.data.SQLite;
	
	import flash.filesystem.File;

	/**
	 * 拼音输入法 
	 * 
	 * 
	 */	
	public class PinYin
	{
		private var _sql:SQLite;
		
		public function PinYin() 
		{
			var file:File = File.applicationDirectory.resolvePath("pinyin.db");
			file.canonicalize();
			
			if(file.exists==false)
			{
				trace("找不到 pinyin.db");
				return;
			}
			
			_sql = new SQLite(file ,null);
		}		
		
		/**
		 * 获得词的列表
		 * 
		 */
		public function getString(value:String):Array
		{
			if(_sql == null)
			{
				trace("找不到 pinyin.db");
				return null;
			}
			
			var result:Array = _sql.fuzzyQuery("char" ,"key" ,value ,SQLite.LIKE_BEGIN ,["list"]);
			if(result==null)return null;
			
			var i:int=0;
			var arr:Array = new Array();
			while(i<result.length)
			{
				var listArr:Array = result[i].list.toString().replace(/\s/g,"").split(",");
				var j:int=0;
				while(j<listArr.length)
				{
					if(listArr[j].length>0)
						arr.push(listArr[j]);
					j++;
				}
				i++;
			}
			return arr;
		}
	}
}